import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Dialogs 1.3
//智能调节参数调节模块
Item {
    id: glht
    anchors.fill: parent
    //后台管理背景
    Image {
        id: hjjkbj5
        source: "/huanjingjkong_5.bmp"
        anchors.fill: parent
        MouseArea {//返回
            x: 0
            y: 0
            width: 90
            height: 80
            onClicked: {
                rootLoader.source = "Huanjingjkong.qml"
            }
        }
        //自动调节开关模块
        Rectangle {
            id: znkzrec
            x:120
            y:100
            radius: 10
            color: "#1d3cc3"
            width: 400
            height: 60
            Text {
                id: text
                text: qsTr("智能自动调节")
                color: "red"
                anchors.left: parent.left
                anchors.leftMargin: 10
                font.pixelSize: 30
                anchors.verticalCenter: parent.verticalCenter
            }
            Switch {
                id: switc
                anchors.right: parent.right
                anchors.rightMargin: 10
                anchors.verticalCenter: parent.verticalCenter
                checked: winroot.switchbool
                onCheckedChanged: {
                    if (switc.checked) {
                        tjcsrec.visible = true
                        qd.visible = true
                        winroot.switchbool = true
                        rootdata.znkz = 0
                    } else {
                        tjcsrec.visible = false
                        winroot.switchbool = false
                        qd.visible = false
                        rootdata.znkz = -1
                        rootdata.my_send(1,-1,-1,-1,-1)
                    }
                }
            }
        }

        //相关参数设置模块
        Rectangle {
            id: tjcsrec
            anchors.top: znkzrec.bottom
            anchors.topMargin: 20
            anchors.left: znkzrec.left
            height: 290
            width: 600
            radius: 10
            visible: false
            color: "#1d3cc3"
            Text {
                id: cssz
                text: qsTr("参数设置")
                anchors.top: parent.top
                anchors.topMargin: 10
                color: "#ffffff"
                anchors.horizontalCenter: parent.horizontalCenter
            }
            //具体参数分块
            Rectangle {
                anchors.top: cssz.bottom
                anchors.topMargin: 10
                anchors.left: parent.left
                anchors.leftMargin: 5
                width: 280
                height: 100
                color: "#1d3cc3"
                border.color: "#ffffff"
                radius: 10
                border.width: 3
                Text {
                    id: tex
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 5
                    text: qsTr("温度设置:")
                }
                SpinBox{
                    id: wdbox
                    anchors.left: tex.right
                    anchors.leftMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                    from: 0
                    to: 50
                    stepSize: 1
                    Component.onCompleted: {
                        value = winroot.bzwd
                    }
                }
                Text {
                    id: texdw
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: wdbox.right
                    anchors.leftMargin: 5
                    text: qsTr("℃")
                }
            }

            Rectangle {
                id: sdrec
                anchors.top: cssz.bottom
                anchors.topMargin: 10
                anchors.right: parent.right
                anchors.rightMargin: 5
                width: 280
                height: 100
                color: "#1d3cc3"
                border.color: "#ffffff"
                radius: 10
                border.width: 3
                Text {
                    id: tex1
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 5
                    text: qsTr("湿度设置:")
                }
                SpinBox{
                    id: wdbox1
                    anchors.left: tex1.right
                    anchors.leftMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                    from: 0
                    to: 100
                    stepSize: 1
                    Component.onCompleted: {
                        value = winroot.bzsd
                    }
                }
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: wdbox1.right
                    anchors.leftMargin: 5
                    text: qsTr("%")
                }
            }
            Rectangle {
                anchors.top: sdrec.bottom
                anchors.topMargin: 10
                anchors.left: parent.left
                anchors.leftMargin: 5
                width: 280
                height: 100
                color: "#1d3cc3"
                border.color: "#ffffff"
                radius: 10
                border.width: 3
                Text {
                    id: tex2
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 5
                    text: qsTr("光照强度设置:")
                }
                SpinBox{
                    id: wdbox2
                    anchors.left: tex2.right
                    anchors.leftMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                    from: 0
                    to: 100
                    stepSize: 1
                    Component.onCompleted: {
                        value = winroot.bzgz
                    }
                }
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: wdbox2.right
                    anchors.leftMargin: 5
                    text: qsTr("%")
                }
            }
            Rectangle {
                anchors.top: sdrec.bottom
                anchors.topMargin: 10
                anchors.right: parent.right
                anchors.rightMargin: 5
                width: 280
                height: 100
                color: "#1d3cc3"
                border.color: "#ffffff"
                radius: 10
                border.width: 3
                Text {
                    id: tex3
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 5
                    text: qsTr("可燃性气体设置:")
                }
                SpinBox{
                    id: wdbox3
                    anchors.left: tex3.right
                    anchors.leftMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                    from: 0
                    to: 100
                    stepSize: 1
                    Component.onCompleted: {
                        value = winroot.bzqt
                    }
                }
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: wdbox3.right
                    anchors.leftMargin: 5
                    text: qsTr("%")
                }
            }
        }
        //设置弹窗模块
        MessageDialog {
            id:id_mesDialog1
            title: "设置成功！"
            icon: StandardIcon.Question
            text: "请点击Yes继续！！！"
            standardButtons: StandardButton.Yes
            Component.onCompleted: visible = false
        }
        MessageDialog {
            id:id_mesDialog2
            title: "设置失败！"
            icon: StandardIcon.Question
            text: "网络未连接！！！"
            standardButtons: StandardButton.Yes
            Component.onCompleted: visible = false
        }
        //确认按钮模块
        Button {
            id: qd
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.rightMargin: 10
            anchors.bottomMargin: 10
            visible: false
            Text {
                id: texb
                anchors.centerIn: parent
                text: qsTr("确定")
            }
            onClicked: {
                winroot.bzwd = wdbox.value
                winroot.bzsd = wdbox1.value
                winroot.bzgz = wdbox2.value
                winroot.bzqt = wdbox3.value
                var ret = rootdata.my_send(1,wdbox.value, wdbox1.value, wdbox2.value, wdbox3.value)
                if (ret === -1) {
                    id_mesDialog2.open()
                }else {
                    id_mesDialog1.open()
                }
            }
        }
    }
}
